: Improving ext* sparse image generation: migrating from img2simg to ext2simg_android for ext* filesystem
Hello Community Members,
I would like to propose a change to how we handle sparse image generation for ext* file-systems in OpenEmbedded, specifically moving away from the generic img2simg tool toward the specialised ext2simg_android in the e2fsprogs [contrib/android]
*1) Problem*
Currently, image_types_sparse.bbclass uses img2simg for all file-system types. img2simg is a tool that reads the raw image to find zero-filled blocks.
For ext* file-systems, this is inefficient compared to ext2simg from e2fsprogs [contrib/android] which understands the file-system structure and uses the block bitmap to determine sparse areas.
*2) History*
Previously, 'ext2simg' was bundled within android-tools (v5.1 and older). The utility has since migrated to the e2fsprogs project (contrib/android). However, upstream e2fsprogs does not provide a build system for this tool, and it requires libsparse from android-tools to compile.
*3) Proposed Changes*
To implement this , below approach is proposed for feedback:
a. meta-oe (android-tools):
Export libsparse, libbase, and liblog headers and libraries to the sysroot. Currently, these are often internal to the build. Reorganise header installation to ${includedir}/sparse to match the expected include paths for e2fsprogs contrib tools.
b. meta-oe (ext2simg_android )
Have created an fresh recipe which focus only on getting ext2simg.c compiled with andorid sparse.h
(as per suggestion on first RFC
[email protected] | [RFC] Improving ext* sparse image generation: migrating from img2simg to ext4sparse for ext* filesystem ( https://lists.openembedded.org/g/openembedded-core/topic/rfc_improving_ext_sparse/117715350 ) )
This would link against the exported libsparse from android-tools-native.
c. meta-oe (image_types_sparse.bbclass):
Update CONVERSION_CMD:sparse to detect ext* types.
Use ext2simg from the e2fsprogs [contrib/android] for these types while falling back to img2simg for others (like f2fs).
*4) Points for Discussion / Feasibility*
I am seeking feedback on the following:
*a. Build Integration:*
In my PoC, I've used a manual ${CC} call in do_compile:append.
Would it be preferred to patch the e2fsprogs Makefile to handle this "contrib" tool more natively?
*b. Library Handling:*
To ensure the native binary finds libsparse at image creation time, I am currently using LD_LIBRARY_PATH in the class. I suspect a better approach would be ensuring proper RPATH during the e2fsprogs build.
If members can help for any better way of doing this
*c. I have a working proof of concept using RPI4 build*
Attached along are the patch 001-meta-oe-image_types_sparse-use-ext2simg_android-for-.patch
*5) Logical layout of current POC*
This commit bridges the gap between these two recipes:
1. android-tools:
- Updated to v29.0.6 and masked v5.1.1 to provide modern libraries.
- Modified do_install to export libsparse, libbase, and liblog headers and libraries to the sysroot, enabling external linking.
2. image_types_sparse.bbclass:
- Updated CONVERSION_CMD to branch by filesystem type, calling ext2simg_android specifically for ext* images.
- Exported LD_LIBRARY_PATH to the native sysroot to ensure the ext2simg_android binary can locate its shared dependencies at runtime.
3. Layer Configuration:
- Updated layer.conf to support dynamic-layers for SELinux and synchronized BBMASK entries to prioritize the updated tools.
*6) Benefit :*
This reduces the time and cost involved while flashing Android RFS / Fastboot etc
Even in CI/CD , which all adds to ease of usage and have monetary benefit involved with continous CI/CD
Looking forward to thoughts / feedback from community members
Please do let me know if any specific platform or group needs to be addressed to have such discussion
If there is any specific meeting involved where i can join and explain, please do let me know
I can connect to team members and works as per suggestion from community to fine tune / rework if any specific changes community suggest
Thanks ,
Ashish Kumar Mishra
From 28bb0409b21b64d6dd439a38d41436ea22a694d5 Mon Sep 17 00:00:00 2001
From: AshishKumar Mishra <[email protected]>
Date: Thu, 19 Feb 2026 13:14:22 +0530
Subject: [PATCH] meta-oe: image_types_sparse: use ext2simg_android for ext*
image conversion
Update the sparse image conversion process for ext* filesystems to use ext2simg_android (ext2simg) instead of the generic img2simg tool.
Unlike img2simg, which treats all zero-blocks identically, ext2simg_android leverages e2fsprogs knowledge of the filesystem.
This allows it to mark zero-blocks outside of the ext-filesystem as "don't care" (skip chunks) rather than "fill-with-zeros" (raw chunks) resulting in more optimized and smaller sparse images.
Previously, 'ext2simg' was bundled within android-tools (v5.1 and older). The utility has since migrated to the e2fsprogs project (contrib/android). However, upstream e2fsprogs does not provide a build system for this tool, and it requires libsparse from android-tools to compile.
This commit bridges the gap between these two recipes:
1. android-tools:
- Updated to v29.0.6 and masked v5.1.1 to provide modern libraries.
- Modified do_install to export libsparse, libbase, and liblog headers and libraries to the sysroot, enabling external linking.
2. image_types_sparse.bbclass:
- Updated CONVERSION_CMD to branch by filesystem type, calling ext2simg_android specifically for ext* images.
- Exported LD_LIBRARY_PATH to the native sysroot to ensure the ext2simg_android binary can locate its shared dependencies at runtime.
3. Layer Configuration:
- Updated layer.conf to support dynamic-layers for SELinux and synchronized BBMASK entries to prioritize the updated tools.
This is ver2 implementaion based on suugestion on RFC
https://lists.openembedded.org/g/openembedded-core/topic/rfc_improving_ext_sparse/117715350
Upstream-Status: Pending
--- meta-oe/classes/image_types_sparse.bbclass | 28 ++++--- meta-oe/conf/layer.conf | 13 ++- .../android-tools/android-tools_29.0.6.r14.bb | 51 ++++++++++++ .../e2fsprogs-ext4sparse_1.0.bb | 80 +++++++++++++++++++ 4 files changed, 162 insertions(+), 10 deletions(-) create mode 100644 meta-oe/recipes-devtools/e2fsprogs-ext4sparse/e2fsprogs-ext4sparse_1.0.bb
meta-oe/classes/image_types_sparse.bbclass +19 -9
@@ -12,12 +12,22 @@ CONVERSIONTYPES += "sparse" DELETE_RAWIMAGE_AFTER_SPARSE_CMD ??= "0" CONVERSION_CMD:sparse = " \ - truncate --no-create --size=%${SPARSE_BLOCK_SIZE} "${IMAGE_NAME}.${type}"; \ - img2simg -s "${IMAGE_NAME}.${type}" "${IMAGE_NAME}.${type}.sparse" ${SPARSE_BLOCK_SIZE}; \ - if [ "${DELETE_RAWIMAGE_AFTER_SPARSE_CMD}" = "1" ]; then \ - rm -f ${IMAGE_NAME}.${type};\ - bbwarn "Raw file ${IMAGE_NAME}.${type} removed" ;\ - fi;\ - " - -CONVERSION_DEPENDS_sparse = "android-tools-native" + truncate --no-create --size=%${SPARSE_BLOCK_SIZE} '${IMAGE_NAME}.${type}'; \ + case '${type}' in \ + ext*) \ + export LD_LIBRARY_PATH='${STAGING_LIBDIR_NATIVE}:${LD_LIBRARY_PATH}'; \ + \ + bbwarn 'Running e2fsprogs-derived ext2simg_android..' ; \ + ext2simg_android '${IMAGE_NAME}.${type}' '${IMAGE_NAME}.simg' || bberror 'ext2simg_android failed' \ + ;; \ + *) \ + bbwarn 'Generating sparse image for non-ext filesystem...'; \ + img2simg -s '${IMAGE_NAME}.${type}' '${IMAGE_NAME}.${type}.sparse' ${SPARSE_BLOCK_SIZE}; \ + ;; \ + esac; \ + if [ '${DELETE_RAWIMAGE_AFTER_SPARSE_CMD}' = '1' ]; then \ + rm -f '${IMAGE_NAME}.${type}'; \ + fi; \ +" +CONVERSION_DEPENDS:sparse = "android-tools-native e2fsprogs-ext4sparse-native" +do_image_ext4[depends] += "e2fsprogs-ext4sparse-native:do_populate_sysroot"
meta-oe/conf/layer.conf +12 -1
@@ -12,7 +12,16 @@ BBPATH .= ":${LAYERDIR}" # We have a recipes directory, add to BBFILES -BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend" +# Adding dynamic layers recipes +BBFILES += "\ + ${LAYERDIR}/recipes-*/*/*.bb \ + ${LAYERDIR}/recipes-*/*/*.bbappend \ + ${LAYERDIR}/dynamic-layers/selinux/recipes-*/*/*.bb \ + ${LAYERDIR}/dynamic-layers/selinux/recipes-*/*/*.bbappend \ +" + +# Manually removing default android-tools recipes +BBMASK += "meta-openembedded/meta-oe/recipes-devtools/android-tools/android-tools_5.1.1.r37.bb" BBFILE_COLLECTIONS += "openembedded-layer" BBFILE_PATTERN_openembedded-layer := "^${LAYERDIR}/"
@@ -40,6 +49,8 @@ BBFILES_DYNAMIC += " \ perl-layer:${LAYERDIR}/dynamic-layers/perl-layer/recipes-*/*/*.bbappend \ selinux:${LAYERDIR}/dynamic-layers/selinux/recipes-*/*/*.bb \ selinux:${LAYERDIR}/dynamic-layers/selinux/recipes-*/*/*.bbappend \ + selinux-layer:${LAYERDIR}/dynamic-layers/selinux/recipes-*/*/*.bb \ + selinux-layer:${LAYERDIR}/dynamic-layers/selinux/recipes-*/*/*.bbappend \ " # This should only be incremented on significant changes that will
meta-oe/dynamic-layers/selinux/recipes-devtool/android-tools/android-tools_29.0.6.r14.bb +51 -0
54 lines not on this page · raw message
meta-oe/recipes-devtools/e2fsprogs-ext4sparse/e2fsprogs-ext4sparse_1.0.bb new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.34.1
Personally I don't think that this is a controversial idea. Added a few short notes inline.
Quoted 49 lines · AshishKumar Mishra via lists.openembedded.org
Hello Community Members,
I would like to propose a change to how we handle sparse image generation for ext* file-systems in OpenEmbedded,
specifically moving away from the generic img2simg tool toward the specialisedext2simg_androidin the e2fsprogs [contrib/android]
*1) Problem*
Currently, image_types_sparse.bbclass uses img2simg for all file-system types.
img2simg is a tool that reads the raw image to find zero-filled blocks. For ext* file-systems, this is inefficient compared to ext2simg from e2fsprogs [contrib/android]
which understands the file-system structure and uses the block bitmap to determine sparse areas.
*2) History*
Previously, 'ext2simg' was bundled within android-tools (v5.1 and older). The utility has since migrated to the e2fsprogs project (contrib/android). However, upstream e2fsprogs does not provide a build system for this tool, and it requires libsparse from android-tools to compile.
*3) Proposed Changes*
To implement this , below approach is proposed for feedback:
a. meta-oe (android-tools):
Export libsparse, libbase, and liblog headers and libraries to the sysroot. Currently, these are often internal to the build. Reorganise header installation to ${includedir}/sparse to match the expected include paths for e2fsprogs contrib tools.
b. meta-oe (ext2simg_android)
Have created an fresh recipe which focus only on gettingext2simg.ccompiled with andoridsparse.h
(as per suggestion on first RFC [email protected] | [RFC] Improving ext* sparse image generation: migrating from img2simg to ext4sparse for ext* filesystem
<https://lists.openembedded.org/g/openembedded-core/topic/rfc_improving_ext_sparse/117715350>
)
This would link against the exported libsparse from android-tools-native.
c. meta-oe (image_types_sparse.bbclass):
Update CONVERSION_CMD:sparse to detect ext* types.
Use ext2simg from the e2fsprogs [contrib/android] for these types while falling back to img2simg for others (like f2fs).
Quoted 8 lines
*4) Points for Discussion / Feasibility*
I am seeking feedback on the following:
*a. Build Integration: *
In my PoC, I've used a manual ${CC} call in do_compile:append. Would it be preferred to patch the e2fsprogsMakefileto handle this "contrib" tool more natively?
I'd say it depends on how complex the patch is. If it's a trivial one, a patch could be okay. But usually patch update is a chore that no one likes, and adding these commands to the recipe shows the intent also better.
Quoted 7 lines
*b. Library Handling: *
To ensure the native binary finds libsparse at image creation time, I am currently usingLD_LIBRARY_PATHin the class.
I suspect a better approach would be ensuring proper RPATH during the e2fsprogs build.
If members can help for any better way of doing this
What happens if you add "-Wl,-rpath=../${baselib} -Wl,-rpath=../../${baselib}" (or similar) to LDFLAGS?
Quoted 5 lines
*c. I have a working proof of concept using RPI4 build * Attached along are the patch 001-meta-oe-image_types_sparse-use-ext2simg_android-for-.patch
e2fsprogs-ext4sparse.inc is missing from the attached patch.
Quoted 45 lines
*5) Logical layout of current POC *
This commit bridges the gap between these two recipes:
1. android-tools:
- Updated to v29.0.6 and masked v5.1.1 to provide modern libraries.
- Modifieddo_installto export libsparse, libbase, and liblog headers and libraries to the sysroot, enabling external linking.
2. image_types_sparse.bbclass:
- UpdatedCONVERSION_CMDto branch by filesystem type, callingext2simg_androidspecifically for ext* images.
- ExportedLD_LIBRARY_PATHto the native sysroot to ensure theext2simg_androidbinary can locate its shared dependencies at runtime.
3. Layer Configuration:
- Updated layer.conf to support dynamic-layers for SELinux and synchronized BBMASK entries to prioritize the updated tools.
*6) Benefit :*
This reduces the time and cost involved while flashing Android RFS / Fastboot etc
Even in CI/CD , which all adds to ease of usage and have monetary benefit involved with continous CI/CD
Looking forward to thoughts / feedback from community members
Please do let me know if any specific platform or group needs to be addressed to have such discussion
If there is any specific meeting involved where i can join and explain, please do let me know
I can connect to team members and works as per suggestion from community to fine tune / rework if any specific changes community suggest
Thanks ,
Ashish Kumar Mishra-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#124499): https://lists.openembedded.org/g/openembedded-devel/message/124499
Mute This Topic: https://lists.openembedded.org/mt/117889188/6084445
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Thanks Gyorgy Sarvari
1) w.r.t "What happens if you add "-Wl,-rpath=../${baselib} -Wl,-rpath=../../${baselib}" (or similar) to LDFLAGS?" Will try this and share the observation
2) e2fsprogs-ext4sparse.inc is missing from the attached patch. This is standard e2fsprogs.inc renamed for continuity in recipe
- Ashish
Hi Gyorgy Sarvari ,
w.r.t "What happens if you add "-Wl,-rpath=../${baselib} -Wl,-rpath=../../${baselib}" (or similar) to LDFLAGS?"
Added below in meta-oe/recipes-devtools/e2fsprogs-ext4sparse/e2fsprogs-ext4sparse_1.0.bb as suggested BUILD_LDFLAGS += "-Wl,-rpath,../${baselib} -Wl,-rpath,../../${baselib}" TARGET_LDFLAGS += "-Wl,-rpath,../${baselib} -Wl,-rpath,../../${baselib}"
Can i push the patch now in master for this functionality? or Is there any other process / feedback that i need to work?
Based on additional feedback, can work on the current implementation and share the patches again
Thanks,
Ashish Kumar Mishra
Quoted 11 lines · AshishKumar Mishra via lists.openembedded.org
Hi Gyorgy Sarvari ,
w.r.t "What happens if you add "-Wl,-rpath=../${baselib} -Wl,-rpath=../../${baselib}" (or similar) to LDFLAGS?"
Added below in meta-oe/recipes-devtools/e2fsprogs-ext4sparse/e2fsprogs-ext4sparse_1.0.bb as suggested
BUILD_LDFLAGS+= "-Wl,-rpath,../${baselib} -Wl,-rpath,../../${baselib}"TARGET_LDFLAGS+= "-Wl,-rpath,../${baselib} -Wl,-rpath,../../${baselib}"
...and what happened? Did it work? Afterwards it came to my mind that maybe it needs also $ORIGIN at the start, but that was just a passing thought.
Quoted 3 lines
Can i push the patch now in master for this functionality? or Is there any other process / feedback that i need to work?
It is not necessary to ask for permission to send your patches. Just send them, and if anything needs to be changed, it will be pointed out.
Quoted 16 lines
Based on additional feedback, can work on the current implementation and share the patches again
Thanks,
Ashish Kumar Mishra-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#124798): https://lists.openembedded.org/g/openembedded-devel/message/124798
Mute This Topic: https://lists.openembedded.org/mt/117889188/6084445
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Thanks Gyorgy
- Yes it worked fine
- w.r.t sharing the patch , will share it
I thought that for RFC we need certain acceptance from maintainer / senior members before actually sharing the patch But thanks for clarification , will clean it further and share it
Thanks Again !
- Ashish
________________________________
From: Gyorgy Sarvari <[email protected]>
Sent: Tuesday, March 03, 2026 11:50
To: AshishKumar Mishra <[email protected]>; [email protected] <[email protected]>
Subject: Re: [oe] [RFC_V2] [meta-oe]: Improving ext* sparse image generation: migrating from img2simg to ext2simg_android for ext* filesystem
Caution: "External email, be cautious especially with link(s), attachment(s) or QR code(s)".
Quoted 11 lines · AshishKumar Mishra via lists.openembedded.org
Hi Gyorgy Sarvari ,
w.r.t "What happens if you add "-Wl,-rpath=../${baselib} -Wl,-rpath=../../${baselib}" (or similar) to LDFLAGS?"
Added below in meta-oe/recipes-devtools/e2fsprogs-ext4sparse/e2fsprogs-ext4sparse_1.0.bb as suggested
BUILD_LDFLAGS+= "-Wl,-rpath,../${baselib} -Wl,-rpath,../../${baselib}"TARGET_LDFLAGS+= "-Wl,-rpath,../${baselib} -Wl,-rpath,../../${baselib}"
...and what happened? Did it work? Afterwards it came to my mind that maybe it needs also $ORIGIN at the start, but that was just a passing thought.
Quoted 3 lines
Can i push the patch now in master for this functionality? or Is there any other process / feedback that i need to work?
It is not necessary to ask for permission to send your patches. Just send them, and if anything needs to be changed, it will be pointed out.
Quoted 16 lines
Based on additional feedback, can work on the current implementation and share the patches again
Thanks,
Ashish Kumar Mishra-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#124798): https://ind01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.openembedded.org%2Fg%2Fopenembedded-devel%2Fmessage%2F124798&data=05%7C02%7Cashishkumar.mishra%40bmwtechworks.in%7C3349f5f5499e4df69abd08de78ed0bf2%7C970fa6fd10314cc68c56488f3c61cd05%7C0%7C0%7C639081156658246502%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=i7MjeCWP2Jowue8T1jjb05RE5v7kNpew%2FcEyl%2FBx2Pw%3D&reserved=0<https://lists.openembedded.org/g/openembedded-devel/message/124798>
Mute This Topic: https://ind01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.openembedded.org%2Fmt%2F117889188%2F6084445&data=05%7C02%7Cashishkumar.mishra%40bmwtechworks.in%7C3349f5f5499e4df69abd08de78ed0bf2%7C970fa6fd10314cc68c56488f3c61cd05%7C0%7C0%7C639081156658274819%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=vY%2BJFLn7nOgqDm6CATBiLWCRAMwxBzx9Qq3FeN36Pms%3D&reserved=0<https://lists.openembedded.org/mt/117889188/6084445>
Group Owner: [email protected]
Unsubscribe: https://ind01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.openembedded.org%2Fg%2Fopenembedded-devel%2Funsub&data=05%7C02%7Cashishkumar.mishra%40bmwtechworks.in%7C3349f5f5499e4df69abd08de78ed0bf2%7C970fa6fd10314cc68c56488f3c61cd05%7C0%7C0%7C639081156658294537%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=ZL8%2FsQG1w5oAws4ipjdM1pMRZ4%2FRNmHWmdWiLLWLbPE%3D&reserved=0<https://lists.openembedded.org/g/openembedded-devel/unsub> [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Hi Richard / Gyorgy Sarvari,
I have shared the V3 of this RFC
https://lists.openembedded.org/g/openembedded-devel/message/128353
Can team please consider this for master branch
Thanks ,
Ashish